home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Noise.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.4 KB  |  91 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //////////////////////////////////////////////////////////////////////////////
  18. // Noise.h
  19. //////////////////////////////////////////////////////////////////////////////
  20.  
  21. #ifndef NOISE_H
  22. #define NOISE_H
  23.  
  24. #include <audio.h>
  25. #include <sys/types.h>
  26. #include <sys/prctl.h>
  27. #include <signal.h>
  28. #include <ulocks.h>
  29. #include "Defines.h"
  30. // #include <stdio.h>
  31. // #include <gl/gl.h>
  32. extern "C" {
  33. #include "sample.h"
  34. }
  35.  
  36. struct Sound
  37. {
  38.     float    pitch;
  39.     long    length; // in samples
  40. };
  41.  
  42. class Noise
  43. {
  44. public:
  45.     Noise(const char *filename, int max_usec, Boolean cont = TRUE);
  46.     ~Noise();
  47.  
  48.     void setContinuity(Boolean b) {
  49.         _received_noise = FALSE;
  50.         _continuous = b; };
  51.     
  52.     void play(float pitch, long usec); // pitch >= 0.0, 1.0 = original tone
  53.     void play_now(float pitch, long usec); // not put in the queue
  54.  
  55.     // returns TRUE if this noise is playable (i.e. has a port)
  56.     Boolean playable() {return (Boolean)_port;};
  57.     
  58. protected:
  59.  
  60.     const char * _filename;
  61.     sample * _s;
  62.     ALport _port;
  63.     ALconfig _config;
  64.     long _max_samples; // max samples to play
  65.  
  66.     // FALSE if the process should sleep when the queue is empty
  67.     // TRUE if the process should continue to play the last sound
  68.     Boolean _continuous;
  69.  
  70.     // have we received anything yet?
  71.     Boolean _received_noise;
  72.     
  73.     // fractional ptr into that array, start of next sound
  74.     float _start;
  75.     
  76.     // array used to store the sound to be played
  77.     short * _outsample;
  78.  
  79.     long sample_length(long usec);
  80.     
  81.     void makenoise(float last_pitch, float pitch, long samples);
  82.     
  83.     void audio_handler();
  84.  
  85.     usema_t * _noises_to_play; // number of noises in the queue to play
  86.     int _in, _out; // queue head and tail
  87.     Sound * _queue; // circular buffer of pitches to play
  88. };
  89.  
  90. #endif
  91.